package com.itheima.dubbo.service.impl;

import com.itheima.dubbo.UserInterface;
import com.itheima.dubbo.pojo.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;

/**
 * @Description:
 * @Version: V1.0
 */
//@DubboService(timeout = 2000, methods = {
//    @Method(name = "sayHello", timeout = 4000, retries = 2)
//})
//@DubboService(retries = 0)  // 设置重试次数0
//@DubboService(version = "${dubbo.application.version}")  // 灰度版本
//@DubboService(version = "1.0.1")  // 灰度版本
//@DubboService(loadbalance = "roundrobin", weight=100)
@DubboService
public class UserServiceImpl implements UserInterface {



    @Override
    public User findOne(Long id) {

        User user = new User();
        user.setUsername("张三");
        user.setId(id);
        user.setAge(18);

        // 本端是否为提供端，这里会返回true
//        boolean isProviderSide = RpcContext.getContext().isProviderSide();
//        // 获取调用方IP地址
//        String clientIP = RpcContext.getContext().getRemoteHost();

        String company = RpcContext.getContext().getAttachment("company");
        System.out.println(company);

        int i = 1 / 0;

        return user;
    }

    /**
     * 入门案例
     * @param username
     * @return
     */
    @Override
    public String sayHello(String username) {

//        System.out.println("start: " + new Date());
//        try {
//            Thread.sleep(3000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        System.out.println("end: " + new Date());
        return "Hello Dubbo....." + username;
    }
}
